{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Programming\n", "\n", "## Systematic Decomposition\n", "\n", "Programming Constructs:\n", "\n", "1. Sequential\n", "2. Conditional\n", "3. Iterative\n", "\n", "\n", "\n", "\n", "\n", "## Debugging\n", "\n", "* %exe\n", "* %pc LOCATION, followed by %step\n", "\n", "But that can be tedious if you need to step through 10,000 instructions. Therefore, we introduce the idea of a **breakpoint**.\n", "\n", "```\n", "%help - shows the following:\n", "\n", " %bp [clear | SUSPENDHEX] - show, clear, or set breakpoints\n", " %cont - continue running\n", " %dis [STARTHEX [STOPHEX]] - dump memory as program\n", " %dump [STARTHEX [STOPHEX]] - list memory in hex\n", " %exe - execute the program\n", " %mem HEXLOCATION HEXVALUE - set memory\n", " %pc HEXVALUE - set PC\n", " %reg REG HEXVALUE - set register REG to HEXVALUE\n", " %regs - show registers\n", " %reset - reset LC3 to start state\n", " %step - execute the next instruction, increment PC\n", "```" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " No breakpoints set\n" ] } ], "source": [ "%bp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 3\n", "\n", "Page 168.\n", "\n", "Some data:" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine; use %exe to run.\n" ] } ], "source": [ ".ORIG x3100\n", "0000 0000 0000 0001\n", "0000 0000 0000 0010\n", "1000 0000 0000 0100\n", "0000 0000 0000 0101\n", "0000 0000 0000 1000\n", "0000 0000 0001 0000\n", "0000 0000 0010 0000\n", "0000 0000 0100 0000\n", "0000 0000 1000 0000\n", "0000 0001 0000 0000\n", ".END" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The program from Figure 6.7:" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine; use %exe to run.\n" ] } ], "source": [ ".ORIG x3000\n", "0101000000100000\n", "0001000000100001\n", "0101001001100000\n", "0001001001111011\n", "0101011011100000\n", "0001011011101010\n", "0010100000001001\n", "0110010100000000\n", "0001010010000001\n", "0000010000000101\n", "0001100100100001\n", "0001011011111111\n", "0110010100000000\n", "0000001111111010\n", "0101000000100000\n", "1111000000100101\n", "0011000100000000\n", ".END" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 22\n", "Cycles: 148 (0.000074 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: xFFFB R2: x8004 R3: x0008 \n", "R4: x3102 R5: x0000 R6: x0000 R7: x3010 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Breakpoints\n", "============================================================\n", " 1) x300D: x03FA\n" ] } ], "source": [ "%bp x300D" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "...breakpoint hit at x300D\n", "============================================================\n", "Computation SUSPENDED\n", "============================================================\n", "Instructions: 13\n", "Cycles: 88 (0.000044 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x300D\n", "N: 0 Z: 0 P: 1 \n", "R0: x0001 R1: xFFFB R2: x0002 R3: x0009 \n", "R4: x3101 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "...breakpoint hit at x300D\n", "============================================================\n", "Computation SUSPENDED\n", "============================================================\n", "Instructions: 19\n", "Cycles: 127 (0.000063 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x300D\n", "N: 1 Z: 0 P: 0 \n", "R0: x0001 R1: xFFFB R2: x8004 R3: x0008 \n", "R4: x3102 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ "%cont" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 22\n", "Cycles: 148 (0.000074 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: xFFFB R2: x8004 R3: x0008 \n", "R4: x3102 R5: x0000 R6: x0000 R7: x3010 \n" ] } ], "source": [ "%cont" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%bp clear" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%cont" ] } ], "metadata": { "kernelspec": { "display_name": "Calysto LC3", "language": "asm", "name": "calysto_lc3" }, "language_info": { "file_extension": ".asm", "mimetype": "text/x-gas", "name": "gas" } }, "nbformat": 4, "nbformat_minor": 2 }